package com.hmall.search.config;

import com.hmall.search.constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    // 创建交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(MqConstants.ITEM_EXCHANGE, true, false);
    }
    // 创建队列: 新增和修改
    @Bean
    public Queue insertUpdateQueue(){
        return new Queue(MqConstants.ITEM_INSERT_UPDATE_QUEUE, true);
    }
    // 创建队列: 删除
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstants.ITEM_DELETE_QUEUE, true);
    }
    // 绑定队列
    @Bean
    public Binding insertUpdateQueueBinding(){
        return BindingBuilder.bind(insertUpdateQueue()).to(topicExchange()).with(MqConstants.ITEM_INSERT_UPDATE_KEY);
    }
    // 绑定队列
    @Bean
    public Binding deleteQueueBinding(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.ITEM_DELETE_KEY);
    }
}
